package red.ouo.distributedtools.redis.message.config;


import lombok.Data;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import red.ouo.distributedtools.redis.message.core.RedisMessageCore;
import red.ouo.distributedtools.standard.message.QueueEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

@Data
@Component
public class RedisMessageConfig {

    public Map<String, QueueEntity> map = new HashMap<>();

    public QueueEntity getExecutorService(String queueName){
        return map.get(queueName);
    }
    public List<String> getAllQueueName(){
        return new ArrayList<>(map.keySet());
    }

    public RedisMessageConfig registerQueue(String queueName, ExecutorService executorService) {
        Assert.hasLength(queueName, "QueueName NOT NULL");
        map.put(RedisMessageCore.queuePrefix+queueName, QueueEntity.builder()
                .queueName(RedisMessageCore.queuePrefix+queueName)
                .executorService(executorService)
                .build());
        return this;
    }
}

